package com.example.myapplication.activity.listView;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;

import android.widget.ListView;

import com.example.myapplication.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Create By TreeRoot
 * Create Time: 2023/12/27 02:03
 * Class Name: ListViewActivity
 * Description:
 *
 * @author TreeRoot
 */
public class ListViewActivity extends AppCompatActivity {
    private ListView listview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view);
        List<MyOption> list = new ArrayList<>();
        list.add(new MyOption("选项1", R.drawable.apple));
        list.add(new MyOption("选项2", R.drawable.apple));
        list.add(new MyOption("选项3", R.drawable.apple));
        list.add(new MyOption("选项4", R.drawable.apple));
        list.add(new MyOption("选项5", R.drawable.apple));
        listview = findViewById(R.id.listView1);
        CustomAdapter adapter = new CustomAdapter(this, R.layout.list_menu_item, list);
        listview.setAdapter(adapter);

        listview.setOnItemClickListener((parent, view, position, id) -> {
            Drawable drawable = getResources().getDrawable(R.color.green);
            listview.setSelector(drawable);
        });
    }

}